<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ include file="/WEB-INF/jsp/common/include.jsp"%>
<script language="JavaScript" type="text/JavaScript">
function changeSearcher()
{
   if(document.getElementById("fixRecord.equipCode").value==''){
    document.getElementById("equipName").value="";
   }else{
    // for(var i=0;i<document.form1.fixRecord.equipCode.options.length;i++) 
    var equipCode = document.getElementById("fixRecord.equipCode").value;
    //alert(equipCode);
    EquipDao.getEquipName(equipCode, callBackForSearcher);  
   }
}

function callBackForSearcher(data)
{
	// alert("the return value is " + data);
	document.getElementById("equipName").value=data;
}


function findResponsers()
{
   if(document.getElementById("fixRecord.issueCode").value==''){
    document.getElementById("fixRecord.responser1Id").value="";
   }else{
    // for(var i=0;i<document.form1.fixRecord.equipCode.options.length;i++) 
    var issueCode = document.getElementById("fixRecord.issueCode").value;
    // alert(issueCode);
    IssueResponseDao.findResponsersByIssueCode(issueCode, callBackForResponser);  
   }
}

function callBackForResponser(data)
{   
	var objResponsers = document.getElementById("fixRecord.responser1Id");
	objResponsers.options.length = 0;
	// 知道属性名称时，使用如下方法	
	for(var i=0;i<data.length;i++)
	{ 
     	var k=i;
     	if (data.length>1)
     	{     		
     		k=i+1;
     		if (k=1)
     		{
	     		var varItem0 = new Option("请选择", "");
				objResponsers.options.add(varItem0);
			}
     	}
     	var varItem = new Option((data[i].lastName+data[i].firstName), data[i].personId);
		objResponsers.options.add(varItem);
		// alert("成功加入");
	}
}

function jsAddItemToSelect(objSelect,objItemText,objItemValue)
{
    //判断是否存在
    if(jsSelectIsExitItem(objSelect,objItemValue))
    {
        alert("该Item的Value值已经存在");
	}
	else
	{
		var varItem = new Option(objItemText,objItemValue);
		// objSelect.options[objSelect.options.length] = varItem;
		objSelect.options.add(varItem);
		alert("成功加入");
	} 
}

</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>设备维修</title>
</head>
<body>    
    <h2>
         	新增一条设备维修记录
    </h2>
    <s:head theme="ajax"/>
    <s:form action="SaveRecord">
        <s:hidden name="fixRecord.recStatus" value="INPR"></s:hidden>
        <s:textfield name="fixRecord.fixRecordCode" label="维修单号"/>
        <s:datetimepicker name="fixRecord.recordDate" label="日期" displayFormat="yyyy-MM-dd" value="today"/>    
        <s:select name="fixRecord.shift" label="班次" tooltip="选择班次"  
                  list="shifts" listKey="domainValue" listValue="domainValue" 
                  required="true" />
		<s:select name="fixRecord.workGroup" label="班组" tooltip="选择班组" 
				  list="workgroups" listKey="domainValue" listValue="domainValue"  
				  required="true" />       				  
        <s:select name="fixRecord.equipCode" label="设备代码" tooltip="选择设备" 
				  list="equips" listKey="equipCode" listValue="equipCode"  
				  headerKey="0" headerValue="请选择"
				  required="true" onchange="changeSearcher()"/>
		<s:textfield name="equipName"/>        
        <s:select name="fixRecord.issueCode" label="故障" tooltip="选择故障" 
				  list="issues" listKey="issueCode" listValue="issueName"  
				  headerKey="0" headerValue="请选择"
				  required="true" onchange="findResponsers()"/>
	    <s:datetimepicker name="fixRecord.issueStart" label="故障开始时间" displayFormat="yyyy-MM-dd" value="today"/>
	    <s:select name="fixRecord.responser1Id" label="故障响应人" tooltip="选择故障响应人" 
				  list="persons" listKey="personId" listValue="firstName"  
				  headerKey="0" headerValue="请选择"
				  required="true"/>      
        <s:submit />
    </s:form>
</body>
</html>

